#include <iostream>
#include <cstring>
using namespace std;

int v[1010], w[1010];
int dp[1010];

int main()
{
    int n, V;
    cin >> n >> V;
    for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
    for (int i = 1; i <= n; i++)
    {
        for (int j = v[i]; j <= V; j++)
        {
            if (j >= v[i]) dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    cout << dp[V] << endl;
    memset(dp, 0, sizeof dp);
    for (int j = 1; j <= V; j++) dp[j] = -0x3f3f3f3f;
    for (int i = 1; i <= n; i++)
    {
        for (int j = v[i]; j <= V; j++)
        {
            dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    cout << (dp[V] < 0 ? 0 : dp[V]) << endl;
    return 0;
}